﻿using Dora.Orm.Core.Domain.Entities;
using Dora.Orm.Core.Domain.Repositories;
using Dora.Orm.SqlSugarCore.UnitOfWork;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;

namespace Dora.Orm.SqlSugarCore.Reponsitory
{
    public interface IDoraSugarRepository<TEntity, in TPrimaryKey> : IRepository<TEntity, TPrimaryKey>
        where TEntity : Entity<TPrimaryKey>
    {
        ISugarQueryable<TEntity> SugarGetAll();
        Task<List<TEntity>> GetAllListAsync();
        Task<List<TEntity>> GetAllListAsync(Expression<Func<TEntity, bool>> predicate);
        Task<ISugarQueryable<TEntity>> FindAllAsync(bool isMaster = false);
        Task<TEntity> InsertAsync(TEntity entity);
        Task<bool> UpdateAsync(TEntity entity);
        Task<bool> UpdateColumnAsync(TEntity entity, Expression<Func<TEntity, object>> funcColums);
        Task<TEntity> GetSingleAsync(Expression<Func<TEntity, bool>> predicate);
        Task<TEntity> FirstOrDefaultAsync(TPrimaryKey id);
        Task<TEntity> FirstOrDefaultAsync(Expression<Func<TEntity, bool>> predicate);
        Task<bool> DeleteAsync(TPrimaryKey id);
        Task<bool> DeleteAsync(TEntity entity);
        Task<bool> DeleteAsync(Expression<Func<TEntity, bool>> predicate);
        Task<TEntity> InsertAndCacheAsync<TCache>(TEntity entity) where TCache : class, new();
        Task<TEntity> UpdateAndCacheAsync<TCache>(TEntity entity) where TCache : class, new();

        Task<bool>DeleteBothOriginAsync(TPrimaryKey id);
        Task<TEntity> GetBothOrginAsync(Expression<Func<TEntity, bool>> predicate, object id);
        Task<TEntity> GetBothOrginAndCacheAsync(Expression<Func<TEntity, bool>> predicate, object id);
    }
}
